package controller;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import dao.XxDao;

/**
* Servlet implementation class XxUserUpdatePwServlet
*/
@WebServlet("/XxUserUpdatePwServlet")
public class XxUserUpdatePwServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public XxUserUpdatePwServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
boolean b = false; // 初始化返回值为 false
String id = request.getParameter("id");
String password = request.getParameter("password");
String page = request.getParameter("page");
// 设置响应内容类型
response.setContentType("text/html;charset=UTF-8");
XxDao dao = new XxDao(); 
//将数据写入数据库
b=dao.updatePassword(id,password);
//修改成功，弹出成功提示框
if(b==true){ 
if(page.equals("1")){
response.sendRedirect("View_Msg/msgStudent.jsp");
}else if(page.equals("2")){
response.sendRedirect("View_Msg/msgFdy.jsp");
}else if(page.equals("3")){
response.sendRedirect("View_Msg/msgSg.jsp");
}else if(page.equals("4")){
response.sendRedirect("View_Msg/msgWy.jsp");
}
}else {
System.out.print("密码修改失败 ");
}
}

}
